/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cp2004_assignment2;

import java.io.*;

/**
 *
 * @author zhaoyingxi JCU Student Number: 11839209
 */
public class MainUI {

    private static String OPTION_1 = "1: Show list of Products....";//menu:Products
    private static String OPTION_2 = "2: Show list of Inventory....";//menu:Inventories
    private static String OPTION_3 = "3: Show list of Inventory same as products ....";//menu:Inventory same as products
    private static final int CANCEL = 0;
    private static final int OPTION_1_ID = 1;
    private static final int OPTION_2_ID = 2;
    private static final int OPTION_3_ID = 3;

    public void run() {
        while (true) {      //Display a menu of available commands.
            System.out.println(OPTION_1);           //Output menu OPTION_1
            System.out.println(OPTION_2);           //Output menu OPTION_2
            System.out.println(OPTION_3);           //Output menu OPTION_3:Display the currently available inventory.
            int option = getUserInput();
            switch (option) {                   //Output Kinds of Lists
                case OPTION_1_ID:
                    ProductArr arr = new ProductArr();
                    System.out.println("The Product List:\n" + arr);
                    break;
                case OPTION_2_ID:
                    ItemArr arr_2 = new ItemArr();
                    System.out.println("The Inventory List:\n" + arr_2);
                    break;
                case OPTION_3_ID:
                    ProductArr arr3 = new ProductArr();
                    System.out.println("The Product List:\n" + arr3);
                    System.out.println("Please you choose a item.");
                    break;
                default:
                    return;
            }
        }

    }

    private int getUserInput() {
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            while (str != null) {
                System.out.print("--> Enter<1,2,3 menu number> : ");
                str = in.readLine();
                return Integer.parseInt(str);
                //process(str);
            }
        } catch (IOException e) {
            return CANCEL;
        } catch (NumberFormatException e) {
            return CANCEL;
        }
        return 0;
    }
}
